define(["jquery","bbcare"],function($,$bb){
	var password = {};
	var URL = $bb.baseUrl("followup");
	/**
	 * 修改系统密码成功后的回调函数
	 */
	var ajaxModifyPassWordCallBack = function(data){
		$bb.toastShow("密码修改成功，请使用新密码重新进行登录！",2500);
		setTimeout(function(){
			window.location.href = "login.html";
		},2500);
	}

	/**
	 * 请求修改系统密码
	 */
	var ajaxModifyPassWord = function(params,callback){
		var sessionId = $bb.getSessionStorage("sessionId");
		$bb.ajax({
			url: URL + "followup/change/password/update?sessionId=" + sessionId,
			data:JSON.stringify(params),
			success: function(data){
				if(data.success){ 
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "修改密码失败！");
				}
			}
		});
		
		
	} 

	/**
	 * 点击保存
	 */
	var onSubmitClick = function(){
		//var password = $("#password").val();
		var newPassword = $("#newPassword").val();
		var newPasswordSure = $("#newPasswordSure").val();
		if( !newPassword ){
			$bb.toastShow("请输入新的登录密码！");
		}else if( !newPasswordSure ){
			$bb.toastShow("请确认新的登录密码！");
		}else{
			if( newPassword != newPasswordSure ){
				$bb.toastShow("两次输入新登录密码不一致，请重新输入新登录密码！");
				$("#newPassword").val("").focus();
				$("#newPasswordSure").val("");
			}else{
				var params = {"data":
					{
					"phoneNo":JSON.parse($bb.getSessionStorage("account")).username,
					"passWord":newPassword
					}
				}

				ajaxModifyPassWord(params,ajaxModifyPassWordCallBack);
			}
		}
	}

	password.init = function(){
		var h = $("#content-main").height() - 40 - 42;
		$(".password-box").css({"height":h});
		$("#passwordSubmit").unbind("click");
		$("#passwordSubmit").click(onSubmitClick);
	}

	return password;
});